package com.wei.shopping.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wei.shopping.dao.CommentMapper;
import com.wei.shopping.entrty.PageResult;
import com.wei.shopping.entrty.QueryPageBean;
import com.wei.shopping.pojo.Comment;
import com.wei.shopping.service.CommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class CommentServiceImpl implements CommentService {

    @Resource
    private CommentMapper commentMapper;

    /**
     * 通过商品id查找所有评论
     * @param commid
     * @return
     */
    @Override
    public PageResult findByCommId(String commid, QueryPageBean queryPageBean){
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Comment> byCommId = commentMapper.findByCommId(commid);
        return new PageResult(byCommId.getTotal(),byCommId.getResult());
    }

    /**
     * 添加评论
     * @param comment
     */
    @Override
    public void addComment(Comment comment){
        commentMapper.addComment(comment);
    }
}
